{include file="public/header"/}
{include file="public/left"/}
    <div class="content">
        <div class="crumbs clr">系统管理 <span class="red">> 用户管理</span>
          {if isset($list['id'])}
          <span class="red">> 编辑</span>
          {else /}
          <span class="red">> 新建</span>
          {/if}
        </div>
        <div class="whiteBox">
          {if isset($list['id'])}
            <p class="tittle">编辑用户</p>
          {else /}
            <p class="tittle">新建用户</p>
          {/if}
          <table class="addTab mb20">
            <tr>
              <td>用户名称：</td>
              <td><input type="text" name="user_name" value="{$list.user_name|default=''}"></td>
            </tr>
            <tr>
              <td>密　　码：</td>
              <td><input type="password" name="passwd" value=""></td>
            </tr>
            <tr>
              <td>确认密码：</td>
              <td><input type="password" name="confirmpasswd" value=""></td>
            </tr>
            <tr>
              <td>真实姓名：</td>
              <td><input type="text" name="real_name" value="{$list.real_name|default=''}"></td>
            </tr>
            <tr>
              <td>性　　别：</td>
              <td>
                <select name="sex" id="sex">
                  <option value="0" {if isset($list['sex']) &&  $list['sex'] eq 0 }selected{/if}>请选择性别</option>
                  <option value="1" {if isset($list['sex']) &&  $list['sex'] eq 1 }selected{/if}>男</option>
                  <option value="2" {if isset($list['sex']) &&  $list['sex'] eq 2 }selected{/if}>女</option>
                </select>
              </td>
            </tr>
            <tr>
              <td>权　　重：</td>
              <td><input type="number" name="weight" value="{$list.weight|default=''}"></td>
            </tr>
            <tr>
              <td>出生日期：</td>
              <td><input onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text" name="date_birth" value="{if isset($list['date_birth']) && $list['date_birth'] neq 0 }{$list.date_birth|date='Y-m-d',###}{/if}"></td>
            </tr>
            <tr>
              <td>联系电话：</td>
              <td><input type="text" name="phone" value="{$list.phone|default=''}"></td>
            </tr>
            <tr>
              <td>邮　　箱：</td>
              <td><input type="text" name="email" value="{$list.email|default=''}"></td>
            </tr>
            <tr>
              <td>选择角色：</td>
              <td>
                <select name="role" id="role">
                  <option value="0" >请选择角色</option>
                  {volist name="role" id='item' key="key"}
                    <option value="{$item.id}" {if isset($list['roleid']) &&  $list['roleid'] eq $item.id }selected{/if}>{$item.html|default=''}{$item.role_name|default=''}</option>
                  {/volist}
                </select>
              </td>
            </tr>
            <tr>
              <td>是否管理员：</td>
              <td>
                <select name="is_admin" id="is_admin">
                  <option value="2" {if isset($list['is_admin']) &&  $list['is_admin'] eq 2 }selected{/if}>否</option>
                  <option value="1" {if isset($list['is_admin']) &&  $list['is_admin'] eq 1 }selected{/if}>是</option>
                </select>
              </td>
            </tr>
            <tr>
              <td></td>
              <td align="right"><span class="greyBtn return">返回</span><span class="redBtn ml15 submit save">保存</span></td>
            </tr>
          </table>
        </div>
        
    </div>

{include file="public/footer"/}

<script type="text/javascript">
//返回
$('.return').on('click',function() {
  window.history.back();
});
//选择生日
$(".setDay").on("click",function(e){
    e.stopPropagation();
    $(this).lqdatetimepicker({
        css : 'datetime-day',
        dateType : 'D'
    });
});

//选择入职日
$(".jobDay").on("click",function(e){
    e.stopPropagation();
    $(this).lqdatetimepicker({
        css : 'datetime-day',
        dateType : 'D'
    });
});


$('.save').on('click',function(){
  $('.alert').hide();
   var id="{$list.id|default=''}";
   var user_name = $('input[name="user_name"]').val();
   if ($.trim(user_name)=='') {
        layer.alert('请输入用户名称');
        return false;
   }
    var passwd = $('input[name="passwd"]').val();
   var confirmpasswd = $('input[name="confirmpasswd"]').val();

   if ($.trim(passwd)!=$.trim(confirmpasswd)) {
      layer.alert('确认密码与密码不一致');
      return false;
   }
   var real_name = $('input[name="real_name"]').val();
   if ($.trim(real_name)=='') {
        layer.alert('请输入真实姓名');
        return false;
   }
   var sex = $('#sex option:selected').val()
   if ($.trim(sex)=='0') {
        layer.alert('请选择性别');
        return false;
   }
   var weight = $('input[name="weight"]').val();
   var date_birth = $('input[name="date_birth"]').val();
   var date_entry = $('input[name="date_entry"]').val();
   var phone = $('input[name="phone"]').val();
   if(isMobel(phone)==false && $.trim(phone)!=''){
      layer.alert('请输入正确的联系电话');
      return false;
   }
   var email = $('input[name="email"]').val();
   if($.trim(email)=='') {
      layer.alert('请输入邮箱地址');
      return false;
   }
   if(isEmail(email)==false){
      layer.alert('请输入正确的邮箱地址');
      return false;
   }
   var role = $('#role option:selected').val();
   var rolename = $('#role option:selected').text();
   var is_admin = $('#is_admin option:selected').val();

   $.post("{:url('admin/user/addAjax')}", {
      id : id,
      user_name : user_name,
      password : passwd,
      real_name : real_name,
      sex : sex,
      weight : weight,
      date_birth : date_birth,
      date_entry : date_entry,
      phone : phone,
      email : email,
      role : role,
      rolename : rolename,
      is_admin : is_admin,
   }, function(data){
      if(data.code==1){
        layer.alert(data.msg, function(index){
          location.href = "{:url('admin/user/index')}";
        });
      }else if(data.code==2){
        layer.alert(data.msg);
        return false;
      }else if(data.code==3){
        layer.alert(data.msg, function(index){
          location.href = "{:url('admin/user/index')}";
        });
      }else{
        layer.alert(data.msg);
        return false;
      }
   }, 'json');
});
</script>
</body>
</html>
    